import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

let activeType = 0
if(window.localStorage.getItem('activeType')){
    activeType = window.localStorage.getItem('activeType')
}else{
    window.localStorage.setItem('activeType',activeType)
}


const store = new Vuex.Store({
    state:{
        activeType:activeType,
        role:window.localStorage.getItem('role'),
        userInfo:{
            user_id:1,
            user_name:"muskli",
            role_id:1,
            role_name:'超级管理员'
        },
        roleData:[
            {id:1,name:'超级管理员',ident:'superAdmin'},
            {id:2,name:'管理员',ident:'admin'},
            {id:3,name:'普通用户',ident:'user'}
        ],
        adminActiveMenu:localStorage.getItem('adminActiveMenu')||101
    },
    getters:{
        
    },
    mutations:{
        SET_ACTIVETYPE(state,type){
            window.localStorage.setItem('activeType',type)
            state.activeType = type;
        },
        SET_ADMIN_ACTIVE_MENU(state,num){
            window.localStorage.setItem('adminActiveMenu',num)
            state.adminActiveMenu = num;
        },
        SET_ROLEID(state,id){
            window.localStorage.setItem('role_id',id)
            state.userInfo.role_id = id;
        },
        SET_USER_INFO(state,obj){
            state.userInfo = obj;
            window.localStorage.setItem('user_id',obj.user_id)
        }
    }
})

export default store